﻿namespace Hidistro.UI.Web.Admin
{
    using Hidistro.ControlPanel.Commodities;
    using Hidistro.ControlPanel.Store;
    using Hidistro.Entities.Commodities;
    using Hidistro.Entities.VShop;
    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using System.Web;
    using System.Linq;

    public class VsiteHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string str = context.Request.Form["actionName"];
            string s = string.Empty;
            string str4 = str;
            if (str4 != null)
            {
                if (!(str4 == "Topic"))
                {
                    if (str4 == "Vote")
                    {
                        s = JsonConvert.SerializeObject(StoreHelper.GetVotes());
                    }
                    else if (str4 == "Category")
                    {
                        s = JsonConvert.SerializeObject(from item in CatalogHelper.GetMainCategories() select new { CateId = item.CategoryId, CateName = item.Name });
                    }
                    else if (str4 == "Activity")
                    {
                        Array values = Enum.GetValues(typeof(LotteryActivityType));
                        List<EnumJson> list2 = new List<EnumJson>();
                        foreach (Enum enum2 in values)
                        {
                            EnumJson json = new EnumJson {
                                Name = enum2.ToShowText(),
                                Value = enum2.ToString()
                            };
                            list2.Add(json);
                        }
                        s = JsonConvert.SerializeObject(list2);
                    }
                    else if (str4 == "ActivityList")
                    {
                        string str3 = context.Request.Form["acttype"];
                        LotteryActivityType type = (LotteryActivityType) Enum.Parse(typeof(LotteryActivityType), str3);
                        if (type == LotteryActivityType.SignUp)
                        {
                            s = JsonConvert.SerializeObject(from item in VShopHelper.GetAllActivity() select new { ActivityId = item.ActivityId, ActivityName = item.Name });
                        }
                        else
                        {
                            s = JsonConvert.SerializeObject(VShopHelper.GetLotteryActivityByType(type));
                        }
                    }
                }
                else
                {
                    s = JsonConvert.SerializeObject(VShopHelper.Gettopics());
                }
            }
            context.Response.Write(s);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private class EnumJson
        {
            public string Name { get; set; }

            public string Value { get; set; }
        }
    }
}

